package com.vench.teddy.service.impl;

import com.vench.teddy.pojo.entity.UserPO;
import com.vench.teddy.repository.UserRepository;
import com.vench.teddy.service.IThreadPoolUserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @Author:vench
 * @Date:2024-09-28 20:18
 */
@Service
@AllArgsConstructor
@Slf4j
public class ThreadPoolUserServiceImpl implements IThreadPoolUserService {

    private final UserRepository repository;
    @Override
    @Async("threadPoolExecutor")
    public void saveAll(List<UserPO> userPOList, CountDownLatch countDownLatch) {
        try {
            repository.saveAll(userPOList);
        }finally {
            countDownLatch.countDown();
        }
    }
}
